package com.bdqn.ch03.service.impl;

import com.bdqn.ch03.SL.SimpleDaoFactory;
import com.bdqn.ch03.mapper.NewsDao;
import com.bdqn.ch03.mapper.impl.NewsDaoImpl;
import com.bdqn.ch03.pojo.News;
import com.bdqn.ch03.service.NewsService;

/**
 * NewsServiceImpl
 *
 * @aurhor Administrator  whs
 * @since 2024/7/1
 */
public class NewsServiceImpl implements NewsService {

//    // 调用数据访问层接口中的sava方法
//    NewsDao newsDao = new NewsDaoImpl();
//    private NewsDao dao = SimpleDaoFactory.getInstance();

    // 示例3
    private NewsDao dao;

    public void setDao(NewsDao dao){
        this.dao = dao;
    }
    public void addNews(News news){
        //调用NewsDao的方法保存新闻信息
        dao.save(news);
    }


    /**
     * 保存新闻信息的方法
     *
     * @param news
     */
    @Override
    public void save(News news) {
       //调用NewsDao保存方法保存信息
        dao.save(news);
//         调用NewsDao接口中的save方法完成保存新闻信息操作
//         newsDao.save(news);


    }
}
